package com.lanou3g.HW_0514;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Properties;

/**
 * Created by dllo on 18/5/14.
 */
@WebServlet(name = "DispatchServlet", urlPatterns = "/a")
public class DispatchServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


        // 对request 和response 的操作是不分 get/post请求的
        response.setContentType("text/html;charset=utf-8");
        // 使用utf-8 来解析body中的参数
        request.setCharacterEncoding("utf-8");

        // 获取参数
        String operation = request.getParameter("operation");

        // 校验 登入/注册
        RequestDispatcher rd = null;
        if (operation.equals("login")) {
            rd = request.getRequestDispatcher("/b");
        } else {
            rd = request.getRequestDispatcher("/c");
        }

        rd.forward(request, response);

}

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
